var temp1;
var tst = [];

for(i = 0; i < document.getElementsByTagName("td").length; i++) {
    temp1 = document.getElementsByTagName("td")[i].innerHTML;
    tst.push(temp1);
}

var overAmn;
var thName = tst[32];
var movieName = tst[34];
var movieDate = tst[36];
var movieTime = tst[38];
var pT = tst[44];
var paymentType = tst[52];
var tC = tst[62];
var surcharge = tst[66];
var alreadyRefund = tst[68];
var refundCheck = tst[86];
var thNameSep = thName.split(' ');
var thNameSep2 = thName.split(',');

var cellEDIT = function(number, newvalue) {
  if(number > document.getElementsByTagName("td").length){
  console.log('skipped!');
  }
    else {
    document.getElementsByTagName("td")[number].innerHTML = newvalue;
    }
};

var menuTitle = "<center>Additional Transaction ";
var menuTitle2 = "Information <FORM>";
var  menuGuts = "<input id=\"ID1\" type=\"button\" value=\"Refund  Option\" onclick=\"alert(refundRESULT + amountaction);\" \/><input  id=\"ID2\" type=\"button\" value=\"Refund Policy\"  onclick=\"popup2(RFurl);\" \/><input id=\"ID3\" type=\"button\"  value=\"Search TH Number\" onclick=\"popup(thNumSearch);\"  \/><input id=\"ID4\" type=\"button\" value=\"Void/Hold Script\"  onclick=\"popup2(vHold);\" \/>";
var menuCloser = "<\/center><\/form>";

var wL=(screen.width-400)/2;

var wT=((screen.height-400)/2)-50;

function popup(url) {
winprops='height=400,width=400,top='+wT+',left='+wL+',scrollbars=no,resizable=no,directories=no,location=no';
win=window.open(url, "myPage", winprops);
}

var wL2=(screen.width-550)/2;

var wT2=((screen.height-250)/2)-50;

function popup2(url) {
winprops='height=250,width=550,top='+wT2+',left='+wL2+',scrollbars=yes,resizable=no,directories=no,location=no';
win=window.open(url, "myPage", winprops);
}

var wL3=(screen.width-550)/2;

var wT3=((screen.height-250)/2)-50;

function popup3(url) {
winprops='height=250,width=550,top='+wT3+',left='+wL3+',scrollbars=yes,resizable=yes,directories=no,location=no';
win=window.open(url, "myPage", winprops);
}

var theMenu = (menuTitle + menuTitle2 + menuGuts + menuCloser);

var vHold = 'http://information.toolv.com/FW1/RFP/voidhold.html';
ypUrl = 'www.yellowpages.com/';
ypUrl2 = ypUrl + thNameSep2[thNameSep2.length -2] + '-' +thNameSep2[thNameSep2.length -1] + '/';
ypUrl3 = ypUrl2.replace(/\s+/g, '') + thName;
var thNumSearch = 'http://' + ypUrl3;



    var Googleit = function(term, mod) {
    var gsURL = "http://www.google.com/search?btnI=I'm+Feeling+Lucky&q=";
    var gS = '"' + gsURL + encodeURIComponent(term) + mod + '"';
    return gS;
};

var  thURL = '<a href=' + Googleit(thName, '+Fandango+Fandango') + ';"' +  ' target="_blank">' + thName + '</a> &nbsp;';

cellEDIT(32, thURL);

var thRESULT;
if(thName.search("AMC") > -1) {
    thRESULT = 'AMC';
} else if(thName.search("Regal") > -1) {
    thRESULT = 'Regal';
} else if(thName.search("UA") > -1) {
    thRESULT = 'Regal';
} else if(thName.search("Edwards") > -1) {
    thRESULT = 'Regal';
} else if(thName.search("Cinemark") > -1) {
    thRESULT = 'Cinemark';
} else if(thName.search("Century") > -1) {
    thRESULT = 'Cinemark';
} else if(thName.search("CinéArts") > -1) {
    thRESULT = 'Cinemark';
} else if(thName.search("Reading") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Angelika") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Consolidated") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Pacific Theatre") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Bakersfield Valley") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Carmel Mountain") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("City Cinemas") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Gaslamp Stadium") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Grossmont Center") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Kaahumanu") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Kahala") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Kapolei") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("olau Stadium") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Koko") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Manville") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Mililani") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Pearlridge") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Rohnert") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Tower Theatre") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Town Square Stadium") > -1) {
    thRESULT = 'Reading';
} else if(thName.search("Ward Stadium") > -1) {
    thRESULT = 'Reading';
}  else if(thName.search("Sawmill") > -1) {
    thRESULT = 'Regal';
} else if(thName.search("Hoyts") > -1) {
    thRESULT = 'Regal';
} else if(thName.search("Regency") > -1) {
    thRESULT = 'Regency';
} else if(thName.search("AmStar") > -1) {
     thRESULT = 'Southern';
} else if(thName.search("The Grand") > -1) {
     thRESULT = 'Southern';
} else if(thName.search("The Theatres at Canal Place") > -1) {
     thRESULT = 'Southern';
} else if(thName.search("Cinebarre") > -1) {
    thRESULT = 'Cinebarre';
} else if(thName.search("Cinedome") > -1) {
    thRESULT = 'Cinemark';
} else if(thName.search("Lufkin Mall") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("Marion Theatre") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("MNM") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("Carmike") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("Movies 278") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("Movies ATL") > -1) {
    thRESULT = 'Carmike';
} else if(thName.search("Promenade Cinema") > -1) {
    thRESULT = 'Carmike';
} else {
    thRESULT = 'Other';
}

var timeAMPM = movieTime.split(' ');
var timesplit = timeAMPM[0].split(':');
var date2numarray = movieDate.split('/');
var dateclean = date2numarray[2].split(' ');
var hrint = parseInt(timesplit[0]);
var minint = parseInt(timesplit[1]);
var totalcostconvert = pT.split('$');
var gettotalpiece = totalcostconvert[1];
var totalinteger = parseInt(gettotalpiece);




function convertToMilitaryTime(ampm, hours) {     
var militaryHours;     
if( ampm == "AM" ) {         
militaryHours = hours;         
if( militaryHours == "12" ) {
militaryHours = "00";
}     
}
else {         
if( ampm == "PM" || am == "p.m." ) {
tempHours = parseInt( hours ) + 2;             
if( tempHours < 10 ) tempHours = "1" + tempHours;             
else tempHours = "2" + ( tempHours - 10 );             
if( tempHours == "24" ) {
tempHours = "12";
}             
militaryHours = tempHours;    
}     
}
return militaryHours;
}
var addmilitary;        
var addmilitary2 = convertToMilitaryTime(timeAMPM[1], hrint);
addmilitary2 = addmilitary2.toString();
addmilitary = addmilitary2.substring(0,2);
addmilitary = parseInt(addmilitary,10);


var monthastext;

var TimeZone;
if(thName.search(" CA") > -1) {
    addmilitary = addmilitary + 3;
    TimeZone = 'PST';
} else if(thName.search(" WA") > -1) {
    addmilitary = addmilitary + 3;
    TimeZone = 'PST';
} else if(thName.search(" OR") > -1) {
    addmilitary = addmilitary + 3;
    TimeZone = 'PST';
} else if(thName.search(" NV") > -1) {
    addmilitary = addmilitary + 3;
    TimeZone = 'PST';
}

else if(thName.search(" MT") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" ID") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" WY") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" UT") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" CO") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" AZ") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
} else if(thName.search(" NM") > -1) {
    addmilitary = addmilitary + 2;
    TimeZone = 'MST';
}

else if(thName.search(" ND") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" SD") > -1) {
    addmilitary = addmilitary + 1;
} else if(thName.search(" NE") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" KS") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" OK") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" TX") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" LA") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" AR") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" MO") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" IA") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" MN") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" WI") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" IL") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" KY") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" MS") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" AL") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
} else if(thName.search(" TN") > -1) {
    addmilitary = addmilitary + 1;
    TimeZone = 'CST';
}

else if(thName.search(" AK") > -1) {
    addmilitary = addmilitary + 4;
    TimeZone = 'AKST';
}

else if(thName.search(" HI") > -1) {
    addmilitary = addmilitary + 5;
    TimeZone = 'HST/HAST';
} else {}
if(TimeZone === 'PST') {
    cellEDIT(38, movieTime + ' >> PST -3hr');
} else if(TimeZone === 'AKST') {
    cellEDIT(38, movieTime + '  >> AKST -4hr');
} else if(TimeZone === 'HST/HAST') {
    cellEDIT(38, movieTime + ' >> HST/HAST -5hr');
} else if(TimeZone === 'CST') {
    cellEDIT(38, movieTime + ' >> CST -1hr');
} else if(TimeZone === 'MST') {
    cellEDIT(38, movieTime + ' >> MST -2hr');
}

var mDay = parseInt(date2numarray[1]);
if (addmilitary >= 24){
addmilitary  =  addmilitary -24;
addmilitary = parseInt(addmilitary,10);
mDay = mDay + 1;
}
else{
}
var num2mo = function(i) {
    if(i === '1') {
        monthastext = 'January ';
    } else if(i === '2') {
        monthastext = 'February ';
    } else if(i === '3') {
        monthastext = 'March ';
    } else if(i === '4') {
        monthastext = 'April ';
    } else if(i === '5') {
        monthastext = 'May ';
    } else if(i === '6') {
        monthastext = 'June ';
    } else if(i === '7') {
        monthastext = 'July ';
    } else if(i === '8') {
        monthastext = 'August ';
    } else if(i === '9') {
        monthastext = 'September ';
    } else if(i === '10') {
        monthastext = 'October ';
    } else if(i === '11') {
        monthastext = 'November ';
    } else {
        monthastext = 'December ';
    }
};

var amountaction;
if(totalinteger > 99) {
    amountaction = 'THIS PURCHASE IS OVER $100, Please pull tickets (after repurchase)and submit to Erin.';
    cellEDIT(44, '<span style="background-color: red">' + pT + '<br></span>');
} else if(totalinteger >= 30) {
    amountaction = 'This transaction can only be refunded by a supervisor or refunds Dept.';
    cellEDIT(44, '<span style="background-color: yellow">' + pT + '<br></span>');
} else {
  amountaction = '';
    cellEDIT(44, '<span style="background-color: green"><FONT COLOR="white">' + pT + '<br></span>');
}

num2mo(date2numarray[0]);
var moviedate4js = (monthastext + mDay + ', ' + date2numarray[2] + addmilitary + ':' + timesplit[1] );
testing = moviedate4js.toString();
var finisheddate = new Date(testing);
var currentdate = new Date();
var bashow;
if(finisheddate <= currentdate) {
    bashow = 'after';
     cellEDIT(36, movieDate + ' >>   <FONT  FACE="terminal"><FONT COLOR="red"> <blink> PAST  SHOWTIME!</blink>');
} else {
    bashow = 'before';

}

var txtSOUTHERN = ('NO REFUND -   Fandango cannot issue a refund at any time for any of these theaters! \n(No Exceptions) \n \n \n');
var txtREGb4 = ('CAN REFUND -   Any CU who contacts before show time will have their request handled by Fandango.\nWhen possible the CU should repurchase with Fandango before a refund is processed.\n \n \n');
var txtREG = ('NO REFUND - Any CU who contacts after show time will have their request handled by the theater.\n\nThere are NO REFUNDS after the printed show time. \n\nIn lieu of a refund, Regal is giving the customer passes.   \n \n \n');
var  txtAMCb4 = ('CAN REFUND - AMC does not issue refunds before showtime  only Fandango can refund before show\n\nWhen possible the CU should repurchase with Fandango before a refund is processed. \n \n \n');
var  txtAMC = ('NO REFUND - Refer to theatre for compensation and provide  contact number \n \n \n \n EXCEPTION: PayPal purchase! \n \n \n');
var  txtREGENb4 = ('CAN REFUND - Regency cannot process refunds only  Fandango can process a refund (request repurchase)! \n \n \n');
var  txtREGEN = ('NO REFUND - Once the show time has passed the theater cannot issue any type of compensation. All refunds are then issued by Fandango; however if possible the CU should repurchase tickets for a new show time.\n \n \n');
var  txtCARb4 = ('CAN REFUND - A refund can be processed, exchanges can be  done by theatre before show (request repurchase)! \n \n \n');
var txtCAR = ('CAN REFUND - A refund can be process as the theatre cannot (request repurchase)! \n \n \n');
var txtCINEb4 = ('CAN REFUND - A refund can be processed only after a new puchase was made! \n \n \n');
var  txtCINE = ('NO REFUND - A refund is not available after showtime unless  customer was referred by theatre manager! \n \n \n');
var txtREADb4 = ('CAN REFUND - Theatre can exchange but refund has to be processed by Fandango (request repurchase) \n \n \n');
var  txtREAD = ('NO REFUND - A refund is not available after showtime unless  customer was referred by theatre manager! \n \n \n If the CU was not referred by TM anything under $30 will be denied unless out of CU control \n (Natural disaster etc.) \n \n \n');
var  txtCINEBARRE = ('CAN REFUND - Customer must repurchase for a new time  and date and then a refund can be processed! \n \n \n');
var txtOTHER = ('NO REFUND - Theatre can offer refund/exchange both before and after showtime! \n \n \n');

var RFurl;
var refundRESULT = [];

//FIND REFUND TYPE
if(thRESULT === "Regal") {
RFurl = 'http://information.toolv.com/FW1/RFP/regalRF.html';
    cellEDIT(31, 'Regal Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtREGb4);
  } else {
        refundRESULT.push(txtREG);
        amountaction = '';
        cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
    }
} else if(thRESULT === "AMC") {
RFurl = 'http://information.toolv.com/FW1/RFP/amcRF.html';
    cellEDIT(31, 'AMC Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtAMCb4);
    } else {
        refundRESULT.push(txtAMC);
        cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
        amountaction = '';
    }    
} else if(thRESULT === "Cinemark") {
RFurl = 'http://information.toolv.com/FW1/RFP/cinemarkRF.html';
    cellEDIT(31, 'Cinemark Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtCINEb4);
    } else {
        refundRESULT.push(txtCINE);
        if(totalinteger >= 30){
        cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
        amountaction = '';
}

    }
} else if(thRESULT === "Carmike") {
RFurl = 'http://information.toolv.com/FW1/RFP/carmikeRF.html';
    cellEDIT(31, 'Carmike Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtCARb4);
    }else {
        refundRESULT.push(txtCAR);
    }
} else if(thRESULT === "Reading") {
RFurl = 'http://information.toolv.com/FW1/RFP/readingRF.html';
    cellEDIT(31, 'Reading Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtREADb4);
    } else {
        refundRESULT.push(txtREAD);
        if(totalinteger >= 30){
        cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
        amountaction = '';
}
    }
} else if(thRESULT === "Regency") {
RFurl = 'http://information.toolv.com/FW1/RFP/regencyRF.html';
    cellEDIT(31, 'Regency Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtREGENb4);
    } else {
        refundRESULT.push(txtREGEN);
        if(totalinteger >= 30){
        cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
        amountaction = '';
}
    }
} else if(thRESULT === "Cinebarre") {
RFurl = 'http://information.toolv.com/FW1/RFP/CinebarreRF.html';
    cellEDIT(31, 'Cinebarre Theatre: &nbsp;');
    if(bashow === 'before') {
        refundRESULT.push(txtCINEBARRE);
    } else {
        refundRESULT.push(txtCINEBARRE);
    }
} else if(thRESULT === "Southern") {
RFurl = 'http://information.toolv.com/FW1/RFP/SouthernRF.html';
    cellEDIT(31, 'Southern Theatre: &nbsp;');
    refundRESULT.push(txtSOUTHERN);
    if(totalinteger >= 30){
    cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
    amountaction = ''; 
}

} else {
RFurl = 'http://information.toolv.com/FW1/RFP/otherRF.html';
    refundRESULT.push(txtOTHER);
    cellEDIT(31, 'Other Theatre: &nbsp;');
    if(totalinteger >= 30){
    cellEDIT(44, '<span style="background-color: purple"><FONT COLOR="white">' + pT + '<br></span>');
    amountaction = ''; 
}

}

var REFUNDRESULT = refundRESULT[0];

var bodyholder = document.getElementsByTagName('body')[0].innerHTML;
document.getElementsByTagName('body')[0].innerHTML = bodyholder + theMenu;

if(document.getElementsByTagName("td").length >= 86){
cellEDIT(86, 'REFUNDS DISABLED <br>(please reload before refunding)');
}
else{}
